package org.example;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

public class IMFileReceiverSlice {
    public static void main(String[] args) throws Exception {
        // 创建消费者，并指定消费者组名
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("file_translate_group");
        // 指定NameServer地址
        consumer.setNamesrvAddr("124.71.28.51:9876");
        // 订阅主题
        consumer.subscribe("FileTransferTopic", "*");
        FileProcess fileProcess = new FileProcess();
        // 注册消息监听器
        consumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> {
            for (MessageExt msg : msgs) {
                String key = msg.getKeys();
                String type = key.split("@@")[0];
                if (type.equals("FILE")) {
                    System.out.println(key);
                    fileProcess.receiverFile("D://",msg);
                }
            }
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        });

        // 启动消费者
        System.out.println("Consumer Start");
        consumer.start();
    }
}